package com.sch.www.user.service.impl;

import com.sch.www.entity.SysMenu;
import com.sch.www.entity.SysRoleMenu;
import com.sch.www.user.mapper.SysMenuMapper;
import com.sch.www.user.service.ISysMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sch.www.user.service.ISysRoleMenuService;
import com.sch.www.user.service.ISysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author admin
 * @since 2019-05-20
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {
    @Autowired
    ISysRoleMenuService iSysRoleMenuService;
    @Autowired
    ISysUserRoleService iSysUserRoleService;

    @Override
    public List<SysMenu> listByRoleId(String roleId) {
        List<String> roleIds = new ArrayList<>();
        roleIds.add(roleId);
        return listByRoleIds(roleIds);
    }

    @Override
    public List<SysMenu> listByRoleIds(List<String> roleIds) {
        List<SysRoleMenu> sysRoleMenuList = iSysRoleMenuService.listByRoleIds(roleIds);
        List<String> menuIds = new ArrayList<>();
        sysRoleMenuList.forEach(sysRoleMenu -> menuIds.add(sysRoleMenu.getMenuId()));
        return (List) listByIds(menuIds);
    }

    @Override
    public List<SysMenu> ListByUserId(String userId) {
        List<String> roleIds = new ArrayList<>();
        iSysUserRoleService.listByUserId(userId).forEach(sysUserRole -> roleIds.add(sysUserRole.getRoleId()));
        return listByRoleIds(roleIds);
    }
}
